// JavaScript Document
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}


function doSubmit(formid, redirectto)
{
	$('#working-area').html('saving...');
	$('#'+formid).ajaxForm(function(data){
									//alert(data);
									$('#working-area').html('');
									if(data.trim() == 'success')
									{
										//window.location = redirectto;	
										$("#property-adding").fadeOut();
										$("#property-added").fadeIn();
									}
									else
									{
										
										//alert(data);
										$('#dialog').html(data);
										$('#dialog').dialog('open');

									}
								});
}


/* valums uplaoder script */
function createUploader(uploadScript, templateURL){            
			var running = 0; 
			var images = [];
            var uploader = new qq.FileUploader({
                element: document.getElementById('file-uploader'),
                action: uploadScript,
                debug: true,
				multiple: true,
				//showMessage: true,
				//sizeLimit: 500000,
				onSubmit: function(id, fileName)
						  {
							  running++; 
							  var loadingImageSrc = templateURL + "/images/loading-image.gif";
							  $("#fileNames ul").append('<li id="img-id-'+id+'"><img src="'+loadingImageSrc+'" alt="loading" /></li>');
						  },
						  
				onProgress: function(id, fileName, loaded, total)
							{
								//var per = 100;
								//alert(total);
								//$("#fileNames").append(fileName + "<br>")
								var p = (loaded/total)*400;
								/*$("#progress").append('<li>'+loaded+'/'+total+'='+p+'</li>');*/
								$("#runner").css("width", p);
								
							},
				onCancel: function(id, fileName)
					      {
							$( "#progressbar" ).slideUp();
						  },
				onComplete: function(id, fileName, responseJSON)
					      {
							 images.push(fileName);
							 var uploadedImageSrc = templateURL + "/uploads/"+fileName;
							 $("#fileNames ul li#img-id-"+id).html('<img src="'+uploadedImageSrc+'" alt="'+fileName+'" /><br/><span class="imgName">'+fileName+'</span>');
							 
							 running--;
							 if(running==0){
								 //alert(images);
								 $("#images_list").attr("value", images);
							 }

						  }
							
            });           
        }
		